﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;

namespace Kokomo.Environment.Hosting
{
	[ViewType(typeof(OptionsView))]
	class OptionsViewModel : DocumentViewModel
	{
		private static Theme CreateGreenTheme()
		{
			ResourceDictionary greenResources = new ResourceDictionary();
			greenResources[EditorStyleKeys.WorkspaceBackgroundBrushKey] = new SolidColorBrush(Colors.Green);

			Theme greenTheme = new Theme("Green", greenResources);
			return greenTheme;
		}
		private static Theme CreateRedTheme()
		{
			ResourceDictionary greenResources = new ResourceDictionary();
			greenResources[EditorStyleKeys.WorkspaceBackgroundBrushKey] = new SolidColorBrush(Colors.Red);

			Theme greenTheme = new Theme("Red", greenResources);
			return greenTheme;
		}

		public OptionsViewModel()
		{
			this.Title = UiString.FromString(Messages.OptionsTitle);

			Theme greenTheme = CreateGreenTheme();
			Theme redTheme = CreateRedTheme();
			this.Themes = new Theme[] {
				greenTheme,
				redTheme
			};
		}

		public IEnumerable<Theme> Themes { get; private set; }

		private Theme _selectedTheme;
		public Theme SelectedTheme
		{
			get { return this._selectedTheme; }
			set
			{
				this._selectedTheme = value;
				this.OnSelectedThemeChanged();
			}
		}

		protected virtual void OnSelectedThemeChanged()
		{
			this.OnPropertyChanged("SelectedTheme");

			ResourceDictionary resources = null;
			if (this.SelectedTheme != null)
				resources = this.SelectedTheme.Resources;

			this.ThemeResources = resources;
		}

		private ResourceDictionary _themeResources;
		public ResourceDictionary ThemeResources
		{
			get { return this._themeResources; }
			set
			{
				this._themeResources = value;
				this.OnPropertyChanged("ThemeResources");
			}
		}
	}
}
